
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>使用链接脚本指定内存布局 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-katex/katex.min.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="part4.html" />
    
    
    <link rel="prev" href="part2.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter0/introduction.html">
            
                <a href="../chapter0/introduction.html">
            
                    
                    第零章：实验环境说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter1/introduction.html">
            
                <a href="../chapter1/introduction.html">
            
                    
                    第一章：独立式可执行程序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter1/part1.html">
            
                <a href="../chapter1/part1.html">
            
                    
                    [安装 nightly rust]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter1/part2.html">
            
                <a href="../chapter1/part2.html">
            
                    
                    使用包管理器 cargo 创建 rust binary 项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../chapter1/part3.html">
            
                <a href="../chapter1/part3.html">
            
                    
                    移除标准库依赖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../chapter1/part4.html">
            
                <a href="../chapter1/part4.html">
            
                    
                    [移除 runtime 依赖]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../chapter1/part5.html">
            
                <a href="../chapter1/part5.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="introduction.html">
            
                <a href="introduction.html">
            
                    
                    第二章：最小化内核
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="part1.html">
            
                <a href="part1.html">
            
                    
                    使用目标三元组描述目标平台
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="part2.html">
            
                <a href="part2.html">
            
                    
                    编译、生成内核镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.3" data-path="part3.html">
            
                <a href="part3.html">
            
                    
                    使用链接脚本指定内存布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="part4.html">
            
                <a href="part4.html">
            
                    
                    [重写程序入口点 -start]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="part5.html">
            
                <a href="part5.html">
            
                    
                    [使用 Qemu 运行内核]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="part6.html">
            
                <a href="part6.html">
            
                    
                    封装 SBI 接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="part7.html">
            
                <a href="part7.html">
            
                    
                    [实现格式化输出]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="part8.html">
            
                <a href="part8.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../chapter3/introduction.html">
            
                <a href="../chapter3/introduction.html">
            
                    
                    第三章：中断
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter3/part1.html">
            
                <a href="../chapter3/part1.html">
            
                    
                    rv64 中断介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter3/part2.html">
            
                <a href="../chapter3/part2.html">
            
                    
                    [手动触发断点中断]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter3/part3.html">
            
                <a href="../chapter3/part3.html">
            
                    
                    程序运行上下文环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../chapter3/part4.html">
            
                <a href="../chapter3/part4.html">
            
                    
                    [实现上下文环境保存与恢复]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../chapter3/part5.html">
            
                <a href="../chapter3/part5.html">
            
                    
                    [时钟中断]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../chapter3/part6.html">
            
                <a href="../chapter3/part6.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../chapter4/introduction.html">
            
                <a href="../chapter4/introduction.html">
            
                    
                    第四章：内存管理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter4/part1.html">
            
                <a href="../chapter4/part1.html">
            
                    
                    [物理内存探测与管理]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter4/part2.html">
            
                <a href="../chapter4/part2.html">
            
                    
                    [动态内存分配]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter4/part3.html">
            
                <a href="../chapter4/part3.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../chapter5/introduction.html">
            
                <a href="../chapter5/introduction.html">
            
                    
                    第五章：内存虚拟化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../chapter5/part1.html">
            
                <a href="../chapter5/part1.html">
            
                    
                    页表：从虚拟内存到物理内存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../chapter5/part2.html">
            
                <a href="../chapter5/part2.html">
            
                    
                    [内核初始映射]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../chapter5/part3.html">
            
                <a href="../chapter5/part3.html">
            
                    
                    内核重映射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../chapter5/part4.html">
            
                <a href="../chapter5/part4.html">
            
                    
                    内核重映射实现之一：页表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../chapter5/part5.html">
            
                <a href="../chapter5/part5.html">
            
                    
                    内核重映射实现之二：MemorySet
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../chapter5/part6.html">
            
                <a href="../chapter5/part6.html">
            
                    
                    [内核重映射实现之三：完结]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../chapter5/part7.html">
            
                <a href="../chapter5/part7.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../chapter6/introduction.html">
            
                <a href="../chapter6/introduction.html">
            
                    
                    第六章：内核线程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../chapter6/part1.html">
            
                <a href="../chapter6/part1.html">
            
                    
                    线程状态与保存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../chapter6/part2.html">
            
                <a href="../chapter6/part2.html">
            
                    
                    线程切换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../chapter6/part3.html">
            
                <a href="../chapter6/part3.html">
            
                    
                    内核线程初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../chapter6/part4.html">
            
                <a href="../chapter6/part4.html">
            
                    
                    [内核线程创建与切换测试]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../chapter6/part5.html">
            
                <a href="../chapter6/part5.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../chapter7/introduction.html">
            
                <a href="../chapter7/introduction.html">
            
                    
                    第七章：线程调度
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../chapter7/part1.html">
            
                <a href="../chapter7/part1.html">
            
                    
                    线程池与线程管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../chapter7/part2.html">
            
                <a href="../chapter7/part2.html">
            
                    
                    内核调度线程 idle
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../chapter7/part3.html">
            
                <a href="../chapter7/part3.html">
            
                    
                    线程调度之 Round Robin 算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../chapter7/part4.html">
            
                <a href="../chapter7/part4.html">
            
                    
                    [线程调度测试]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../chapter7/part5.html">
            
                <a href="../chapter7/part5.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter8/introduction.html">
            
                <a href="../chapter8/introduction.html">
            
                    
                    第八章：进程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../chapter8/part1.html">
            
                <a href="../chapter8/part1.html">
            
                    
                    [编写用户程序]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../chapter8/part1_1.html">
            
                <a href="../chapter8/part1_1.html">
            
                    
                    合并内核与应用程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../chapter8/part2.html">
            
                <a href="../chapter8/part2.html">
            
                    
                    在内核中实现系统调用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../chapter8/part3.html">
            
                <a href="../chapter8/part3.html">
            
                    
                    创建虚拟内存空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../chapter8/part4.html">
            
                <a href="../chapter8/part4.html">
            
                    
                    [创建进程]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../chapter8/part5.html">
            
                <a href="../chapter8/part5.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../chapter9/introduction.html">
            
                <a href="../chapter9/introduction.html">
            
                    
                    第九章：文件系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../chapter9/part1.html">
            
                <a href="../chapter9/part1.html">
            
                    
                    [使用文件系统]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../chapter9/part2.html">
            
                <a href="../chapter9/part2.html">
            
                    
                    [实现记事本]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../chapter9/part3.html">
            
                <a href="../chapter9/part3.html">
            
                    
                    [实现终端]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../chapter9/part4.html">
            
                <a href="../chapter9/part4.html">
            
                    
                    [文件读写]
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../chapter9/part5.html">
            
                <a href="../chapter9/part5.html">
            
                    
                    总结与展望
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../chapter10/introduction.html">
            
                <a href="../chapter10/introduction.html">
            
                    
                    第十章：同步互斥
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../exercise/introduction.html">
            
                <a href="../exercise/introduction.html">
            
                    
                    练习题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../exercise/part1.html">
            
                <a href="../exercise/part1.html">
            
                    
                    1. 中断异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../exercise/part2.html">
            
                <a href="../exercise/part2.html">
            
                    
                    2. 物理内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../exercise/part3.html">
            
                <a href="../exercise/part3.html">
            
                    
                    3. 虚拟内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../exercise/part4.html">
            
                <a href="../exercise/part4.html">
            
                    
                    4. 线程管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="../exercise/part5.html">
            
                <a href="../exercise/part5.html">
            
                    
                    5. 用户进程（+ 虚拟内存管理 + 线程管理）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.6" data-path="../exercise/part6.html">
            
                <a href="../exercise/part6.html">
            
                    
                    6. CPU 调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.7" data-path="../exercise/part7.html">
            
                <a href="../exercise/part7.html">
            
                    
                    7. 同步互斥
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.8" data-path="../exercise/part8.html">
            
                <a href="../exercise/part8.html">
            
                    
                    8. 文件系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../appendix/introduction.html">
            
                <a href="../appendix/introduction.html">
            
                    
                    附录
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../appendix/inline_asm.html">
            
                <a href="../appendix/inline_asm.html">
            
                    
                    内联汇编
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../appendix/install_rust.html">
            
                <a href="../appendix/install_rust.html">
            
                    
                    安装 rust
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >使用链接脚本指定内存布局</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x4F7F;&#x7528;&#x94FE;&#x63A5;&#x811A;&#x672C;&#x6307;&#x5B9A;&#x7A0B;&#x5E8F;&#x5185;&#x5B58;&#x5E03;&#x5C40;">&#x4F7F;&#x7528;&#x94FE;&#x63A5;&#x811A;&#x672C;&#x6307;&#x5B9A;&#x7A0B;&#x5E8F;&#x5185;&#x5B58;&#x5E03;&#x5C40;</h2>
<ul>
<li><a href="https://github.com/rcore-os/rCore_tutorial/tree/ch2-pa4" target="_blank">&#x4EE3;&#x7801;</a></li>
</ul>
<p>&#x4E0A;&#x4E00;&#x8282;&#x4E2D;&#x6211;&#x4EEC;&#x770B;&#x5230;&#xFF0C;&#x7F16;&#x8BD1;&#x51FA;&#x7684;&#x7A0B;&#x5E8F;&#x9ED8;&#x8BA4;&#x88AB;&#x653E;&#x5230;&#x4E86;&#x4ECE; 0x10000 &#x5F00;&#x59CB;&#x7684;&#x4F4D;&#x7F6E;&#x4E0A;&#xFF1A;</p>
<pre class="language-"><code>start address: 0x0000000000011000
...
Program Header:
    PHDR off    0x0000000000000040 vaddr 0x0000000000010040 ...
    LOAD off    0x0000000000000000 vaddr 0x0000000000010000 ...
    LOAD off    0x0000000000001000 vaddr 0x0000000000011000 ...
   STACK off    0x0000000000000000 vaddr 0x0000000000000000 ...
</code></pre><p>&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x5BF9;&#x4E8E;&#x666E;&#x901A;&#x7528;&#x6237;&#x7A0B;&#x5E8F;&#x6765;&#x8BF4;&#xFF0C;&#x6570;&#x636E;&#x662F;&#x653E;&#x5728;&#x4F4E;&#x5730;&#x5740;&#x7A7A;&#x95F4;&#x4E0A;&#x7684;&#x3002;</p>
<p>&#x4F46;&#x662F;&#x5BF9;&#x4E8E; OS &#x5185;&#x6838;&#xFF0C;&#x5B83;&#x4E00;&#x822C;&#x90FD;&#x5728;&#x9AD8;&#x5730;&#x5740;&#x7A7A;&#x95F4;&#x4E0A;&#x3002;&#x5E76;&#x4E14;&#x5728; RISCV &#x4E2D;&#xFF0C;&#x5185;&#x5B58;&#xFF08;RAM&#xFF09;&#x7684;&#x7269;&#x7406;&#x5730;&#x5740;&#x4E5F;&#x662F;&#x4ECE; 0x80000000 &#x5F00;&#x59CB;&#x7684;&#x3002;&#x56E0;&#x6B64;&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x8C03;&#x6574;&#x7A0B;&#x5E8F;&#x7684;&#x5185;&#x5B58;&#x5E03;&#x5C40;&#xFF0C;&#x6539;&#x53D8;&#x5B83;&#x7684;&#x94FE;&#x63A5;&#x5730;&#x5740;&#x3002;</p>
<blockquote>
<p><strong>[info] &#x7A0B;&#x5E8F;&#x7684;&#x5185;&#x5B58;&#x5E03;&#x5C40;</strong></p>
<p>&#x4E00;&#x822C;&#x6765;&#x8BF4;&#xFF0C;&#x4E00;&#x4E2A;&#x7A0B;&#x5E8F;&#x6309;&#x7167;&#x529F;&#x80FD;&#x4E0D;&#x540C;&#x4F1A;&#x5206;&#x4E3A;&#x4E0B;&#x9762;&#x8FD9;&#x4E9B;&#x6BB5;&#xFF1A;</p>
<ul>
<li><em>.text</em> &#x6BB5;&#xFF0C;&#x5373;&#x4EE3;&#x7801;&#x6BB5;&#xFF0C;&#x5B58;&#x653E;&#x6C47;&#x7F16;&#x4EE3;&#x7801;&#xFF1B;</li>
<li><em>.rodata</em> &#x6BB5;&#xFF0C;&#x5373;&#x53EA;&#x8BFB;&#x6570;&#x636E;&#x6BB5;&#xFF0C;&#x987E;&#x540D;&#x601D;&#x4E49;&#x91CC;&#x9762;&#x5B58;&#x653E;&#x53EA;&#x8BFB;&#x6570;&#x636E;&#xFF0C;&#x901A;&#x5E38;&#x662F;&#x7A0B;&#x5E8F;&#x4E2D;&#x7684;&#x5E38;&#x91CF;&#xFF1B;</li>
<li><em>.data</em> &#x6BB5;&#xFF0C;&#x5B58;&#x653E;&#x88AB;&#x521D;&#x59CB;&#x5316;&#x7684;&#x53EF;&#x8BFB;&#x5199;&#x6570;&#x636E;&#xFF0C;&#x901A;&#x5E38;&#x4FDD;&#x5B58;&#x7A0B;&#x5E8F;&#x4E2D;&#x7684;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF1B;</li>
<li><em>.bss</em> &#x6BB5;&#xFF0C;&#x5B58;&#x653E;&#x88AB;&#x521D;&#x59CB;&#x5316;&#x4E3A; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span></span></span></span> &#x7684;&#x53EF;&#x8BFB;&#x5199;&#x6570;&#x636E;&#xFF0C;&#x4E0E; <em>.data</em> &#x6BB5;&#x7684;&#x4E0D;&#x540C;&#x4E4B;&#x5904;&#x5728;&#x4E8E;&#x6211;&#x4EEC;&#x77E5;&#x9053;&#x5B83;&#x8981;&#x88AB;&#x521D;&#x59CB;&#x5316;&#x4E3A; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span></span></span></span> &#xFF0C;&#x56E0;&#x6B64;&#x5728;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&#x4E2D;&#x53EA;&#x9700;&#x8BB0;&#x5F55;&#x8FD9;&#x4E2A;&#x6BB5;&#x7684;&#x5927;&#x5C0F;&#x4EE5;&#x53CA;&#x6240;&#x5728;&#x4F4D;&#x7F6E;&#x5373;&#x53EF;&#xFF0C;&#x800C;&#x4E0D;&#x7528;&#x8BB0;&#x5F55;&#x91CC;&#x9762;&#x7684;&#x6570;&#x636E;&#x3002;</li>
<li><em>stack</em> &#xFF0C;&#x5373;&#x6808;&#xFF0C;&#x7528;&#x6765;&#x5B58;&#x50A8;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x8FC7;&#x7A0B;&#x4E2D;&#x7684;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x4EE5;&#x53CA;&#x8D1F;&#x8D23;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x65F6;&#x7684;&#x5404;&#x79CD;&#x673A;&#x5236;&#x3002;&#x5B83;&#x4ECE;&#x9AD8;&#x5730;&#x5740;&#x5411;&#x4F4E;&#x5730;&#x5740;&#x589E;&#x957F;&#xFF1B;</li>
<li><em>heap</em> &#xFF0C;&#x5373;&#x5806;&#xFF0C;&#x7528;&#x6765;&#x652F;&#x6301;&#x7A0B;&#x5E8F;<strong>&#x8FD0;&#x884C;&#x8FC7;&#x7A0B;&#x4E2D;</strong>&#x5185;&#x5B58;&#x7684;<strong>&#x52A8;&#x6001;&#x5206;&#x914D;</strong>&#xFF0C;&#x6BD4;&#x5982;&#x8BF4;&#x4F60;&#x8981;&#x8BFB;&#x8FDB;&#x6765;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5728;&#x4F60;&#x5199;&#x7A0B;&#x5E8F;&#x7684;&#x65F6;&#x5019;&#x4F60;&#x4E5F;&#x4E0D;&#x77E5;&#x9053;&#x5B83;&#x7684;&#x957F;&#x5EA6;&#x7A76;&#x7ADF;&#x4E3A;&#x591A;&#x5C11;&#xFF0C;&#x4E8E;&#x662F;&#x4F60;&#x53EA;&#x80FD;&#x5728;&#x8FD0;&#x884C;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x77E5;&#x9053;&#x4E86;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x957F;&#x5EA6;&#x4E4B;&#x540E;&#xFF0C;&#x518D;&#x5728;&#x5806;&#x4E2D;&#x7ED9;&#x8FD9;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x5206;&#x914D;&#x5185;&#x5B58;&#x3002;</li>
</ul>
<p>&#x5185;&#x5B58;&#x5E03;&#x5C40;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x6307;&#x8FD9;&#x4E9B;&#x6BB5;&#x5404;&#x81EA;&#x6240;&#x653E;&#x7684;&#x4F4D;&#x7F6E;&#x3002;&#x4E00;&#x79CD;&#x5178;&#x578B;&#x7684;&#x5185;&#x5B58;&#x5E03;&#x5C40;&#x5982;&#x4E0B;&#xFF1A;</p>
<p><img src="figures/program_memory_layout.png" style="height:400px"></p>
</blockquote>
<h3 id="&#x7F16;&#x5199;&#x94FE;&#x63A5;&#x811A;&#x672C;">&#x7F16;&#x5199;&#x94FE;&#x63A5;&#x811A;&#x672C;</h3>
<p>&#x6211;&#x4EEC;&#x4F7F;&#x7528; <strong>&#x94FE;&#x63A5;&#x811A;&#x672C;&#xFF08;linker script&#xFF09;</strong>&#x6765;&#x6307;&#x5B9A;&#x7A0B;&#x5E8F;&#x7684;&#x5185;&#x5B58;&#x5E03;&#x5C40;&#x3002;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6587;&#x4EF6; <code>src/boot/linker64.ld</code>&#xFF1A;</p>
<pre class="language-"><code class="lang-clike"><span class="token comment">// src/boot/linker64.ld</span>

<span class="token function">OUTPUT_ARCH</span><span class="token punctuation">(</span>riscv<span class="token punctuation">)</span>
<span class="token function">ENTRY</span><span class="token punctuation">(</span>_start<span class="token punctuation">)</span>

BASE_ADDRESS <span class="token operator">=</span> <span class="token number">0x80200000</span><span class="token punctuation">;</span>

SECTIONS
<span class="token punctuation">{</span>
    <span class="token comment">/* Load the kernel at this address: &quot;.&quot; means the current address */</span>
    <span class="token punctuation">.</span> <span class="token operator">=</span> BASE_ADDRESS<span class="token punctuation">;</span>
    start <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">;</span>

    <span class="token punctuation">.</span>text <span class="token punctuation">:</span> <span class="token punctuation">{</span>
        stext <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">;</span>
        <span class="token operator">*</span><span class="token punctuation">(</span><span class="token punctuation">.</span>text<span class="token punctuation">.</span>entry<span class="token punctuation">)</span>
        <span class="token operator">*</span><span class="token punctuation">(</span><span class="token punctuation">.</span>text <span class="token punctuation">.</span>text<span class="token punctuation">.</span><span class="token operator">*</span><span class="token punctuation">)</span>
        <span class="token punctuation">.</span> <span class="token operator">=</span> <span class="token function">ALIGN</span><span class="token punctuation">(</span><span class="token number">4</span>K<span class="token punctuation">)</span><span class="token punctuation">;</span>
        etext <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token punctuation">.</span>rodata <span class="token punctuation">:</span> <span class="token punctuation">{</span>
        srodata <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">;</span>
        <span class="token operator">*</span><span class="token punctuation">(</span><span class="token punctuation">.</span>rodata <span class="token punctuation">.</span>rodata<span class="token punctuation">.</span><span class="token operator">*</span><span class="token punctuation">)</span>
        <span class="token punctuation">.</span> <span class="token operator">=</span> <span class="token function">ALIGN</span><span class="token punctuation">(</span><span class="token number">4</span>K<span class="token punctuation">)</span><span class="token punctuation">;</span>
        erodata <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token punctuation">.</span>data <span class="token punctuation">:</span> <span class="token punctuation">{</span>
        sdata <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">;</span>
        <span class="token operator">*</span><span class="token punctuation">(</span><span class="token punctuation">.</span>data <span class="token punctuation">.</span>data<span class="token punctuation">.</span><span class="token operator">*</span><span class="token punctuation">)</span>
        edata <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token punctuation">.</span>stack <span class="token punctuation">:</span> <span class="token punctuation">{</span>
        <span class="token operator">*</span><span class="token punctuation">(</span><span class="token punctuation">.</span>bss<span class="token punctuation">.</span>stack<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

    <span class="token punctuation">.</span>bss <span class="token punctuation">:</span> <span class="token punctuation">{</span>
        sbss <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">;</span>
        <span class="token operator">*</span><span class="token punctuation">(</span><span class="token punctuation">.</span>bss <span class="token punctuation">.</span>bss<span class="token punctuation">.</span><span class="token operator">*</span><span class="token punctuation">)</span>
        ebss <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token function">PROVIDE</span><span class="token punctuation">(</span>end <span class="token operator">=</span> <span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x65F6;&#x81F3;&#x4ECA;&#x65E5;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x4E0D;&#x592A;&#x53EF;&#x80FD;&#x5C06;&#x6240;&#x6709;&#x4EE3;&#x7801;&#x90FD;&#x5199;&#x5728;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x91CC;&#x9762;&#x3002;&#x5728;&#x7F16;&#x8BD1;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x7684;&#x7F16;&#x8BD1;&#x5668;&#x548C;&#x94FE;&#x63A5;&#x5668;&#x5DF2;&#x7ECF;&#x7ED9;&#x6BCF;&#x4E2A;&#x6587;&#x4EF6;&#x90FD;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x4E86;&#x4E00;&#x4E2A;&#x5185;&#x5B58;&#x5E03;&#x5C40;&#x3002;&#x8FD9;&#x91CC;&#xFF0C;&#x6211;&#x4EEC;&#x7684;&#x94FE;&#x63A5;&#x5DE5;&#x5177;&#x6240;&#x8981;&#x505A;&#x7684;&#x662F;&#x6700;&#x7EC8;&#x5C06;&#x5404;&#x4E2A;&#x6587;&#x4EF6;&#x7684;&#x5185;&#x5B58;&#x5E03;&#x5C40;&#x88C5;&#x914D;&#x8D77;&#x6765;&#x751F;&#x6210;&#x6574;&#x4E2A;&#x7A0B;&#x5E8F;&#x7684;&#x5185;&#x5B58;&#x5E03;&#x5C40;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x9996;&#x5148;&#x4F7F;&#x7528; <em>OUTPUT_ARCH</em> &#x6307;&#x5B9A;&#x4E86;&#x67B6;&#x6784;&#xFF0C;&#x968F;&#x540E;&#x4F7F;&#x7528; <em>ENTRY</em> &#x6307;&#x5B9A;&#x4E86; <strong>&#x5165;&#x53E3;&#x70B9;</strong> &#x4E3A; <code>_start</code> &#xFF0C;&#x5373;&#x7A0B;&#x5E8F;&#x7B2C;&#x4E00;&#x6761;&#x88AB;&#x6267;&#x884C;&#x7684;&#x6307;&#x4EE4;&#x6240;&#x5728;&#x4E4B;&#x5904;&#x3002;&#x5728;&#x8FD9;&#x4E2A;&#x94FE;&#x63A5;&#x811A;&#x672C;&#x4E2D;&#x6211;&#x4EEC;&#x5E76;&#x672A;&#x770B;&#x5230; <code>_start</code> &#xFF0C;&#x56DE;&#x5FC6;&#x4E0A;&#x4E00;&#x7AE0;&#xFF0C;&#x6211;&#x4EEC;&#x4E3A;&#x4E86;&#x79FB;&#x9664;&#x8FD0;&#x884C;&#x65F6;&#x73AF;&#x5883;&#x4F9D;&#x8D56;&#xFF0C;&#x91CD;&#x5199;&#x4E86; C runtime &#x7684;&#x5165;&#x53E3; <code>_start</code> &#x3002;&#x6240;&#x4EE5;&#xFF0C;&#x94FE;&#x63A5;&#x811A;&#x672C;&#x5BA3;&#x5E03;&#x6574;&#x4E2A;&#x7A0B;&#x5E8F;&#x4F1A;&#x4ECE;&#x90A3;&#x91CC;&#x5F00;&#x59CB;&#x8FD0;&#x884C;&#x3002;</p>
<p>&#x94FE;&#x63A5;&#x811A;&#x672C;&#x7684;&#x6574;&#x4F53;&#x5199;&#x5728; <em>SECTION{ }</em> &#x4E2D;&#xFF0C;&#x91CC;&#x9762;&#x6709;&#x591A;&#x4E2A;&#x5F62;&#x5982; <em>output section:{ input section list }</em> &#x7684;&#x8BED;&#x53E5;&#xFF0C;&#x6BCF;&#x4E2A;&#x90FD;&#x63CF;&#x8FF0;&#x4E86;&#x4E00;&#x4E2A;&#x6574;&#x4E2A;&#x7A0B;&#x5E8F;&#x5185;&#x5B58;&#x5E03;&#x5C40;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x8F93;&#x51FA;&#x6BB5; <em>output section</em> &#x662F;&#x7531;&#x5404;&#x4E2A;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x54EA;&#x4E9B;&#x8F93;&#x5165;&#x6BB5; <em>input section</em> &#x7EC4;&#x6210;&#x7684;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7528; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mo>&#x2217;</mo><mo>(</mo><mo>)</mo></mrow><annotation encoding="application/x-tex">*()</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord">&#x2217;</span><span class="mopen">(</span><span class="mclose">)</span></span></span></span> &#x6765;&#x8868;&#x793A;&#x5C06;&#x5404;&#x4E2A;&#x6587;&#x4EF6;&#x4E2D;&#x6240;&#x6709;&#x7B26;&#x5408;&#x62EC;&#x53F7;&#x5185;&#x8981;&#x6C42;&#x7684;&#x8F93;&#x5165;&#x6BB5;&#x653E;&#x5728;&#x5F53;&#x524D;&#x7684;&#x4F4D;&#x7F6E;&#x3002;&#x800C;&#x62EC;&#x53F7;&#x5185;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x6BB5;&#x7684;&#x540D;&#x5B57;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x901A;&#x914D;&#x7B26; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mo>&#x2217;</mo></mrow><annotation encoding="application/x-tex">*</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.46528em;"></span><span class="strut bottom" style="height:0.46528em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord">&#x2217;</span></span></span></span> &#x3002;</p>
<p>&#x5355;&#x72EC;&#x7684;&#x4E00;&#x4E2A; <code>.</code> &#x4E3A; <strong>&#x5F53;&#x524D;&#x5730;&#x5740; (Location Counter)</strong> &#x3002;&#x53EF;&#x4EE5;&#x5BF9;&#x5176;&#x8D4B;&#x503C;&#xFF0C;&#x4F7F;&#x5176;&#x4ECE;&#x8BBE;&#x7F6E;&#x7684;&#x5730;&#x5740;&#x7EE7;&#x7EED;&#x5411;&#x9AD8;&#x5730;&#x5740;&#x653E;&#x7F6E;&#x5404;&#x4E2A;&#x6BB5;&#x3002;&#x5982;&#x679C;&#x4E0D;&#x8FDB;&#x884C;&#x8D4B;&#x503C;&#x7684;&#x8BDD;&#xFF0C;&#x5219;&#x9ED8;&#x8BA4;&#x5404;&#x4E2A;&#x6BB5;&#x4F1A;&#x7D27;&#x6328;&#x7740;&#x5411;&#x9AD8;&#x5730;&#x5740;&#x653E;&#x7F6E;&#x3002;&#x5C06;&#x4E00;&#x4E2A; <strong>&#x7B26;&#x53F7;</strong> &#x8D4B;&#x503C;&#x4E3A; <code>.</code> &#x5219;&#x4F1A;&#x8BB0;&#x5F55;&#x4E0B;&#x8FD9;&#x4E2A;&#x7B26;&#x53F7;&#x7684;&#x5730;&#x5740;&#x3002;</p>
<p>&#x5230;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x5927;&#x6982;&#x770B;&#x61C2;&#x4E86;&#x8FD9;&#x4E2A;&#x94FE;&#x63A5;&#x811A;&#x672C;&#x5728;&#x505A;&#x4E9B;&#x4EC0;&#x4E48;&#x4E8B;&#x60C5;&#x3002;&#x9996;&#x5148;&#x662F;&#x4ECE; <em>BASE_ADDRESS</em> &#x5373; <code>0x80200000</code> &#x5F00;&#x59CB;&#x5411;&#x4E0B;&#x653E;&#x7F6E;&#x5404;&#x4E2A;&#x6BB5;&#xFF0C;&#x4F9D;&#x6B21;&#x662F; <em>.text, .rodata, .data, .stack, .bss</em> &#x3002;&#x540C;&#x65F6;&#x6211;&#x4EEC;&#x8FD8;&#x8BB0;&#x5F55;&#x4E0B;&#x4E86;&#x6BCF;&#x4E2A;&#x6BB5;&#x7684;&#x5F00;&#x5934;&#x548C;&#x7ED3;&#x5C3E;&#x5730;&#x5740;&#xFF0C;&#x5982; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mtext><mi mathvariant="normal">.</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">x</mi><mi mathvariant="normal">t</mi></mtext></mrow><annotation encoding="application/x-tex">\text{.text}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.61508em;"></span><span class="strut bottom" style="height:0.61508em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord text textstyle uncramped"><span class="mord mathrm">.text</span></span></span></span></span> &#x6BB5;&#x7684;&#x5F00;&#x5934;&#x3001;&#x7ED3;&#x5C3E;&#x5730;&#x5740;&#x5206;&#x522B;&#x5C31;&#x662F;&#x7B26;&#x53F7; <em>stext, etext</em> &#x7684;&#x5730;&#x5740;&#xFF0C;&#x6211;&#x4EEC;&#x63A5;&#x4E0B;&#x6765;&#x4F1A;&#x7528;&#x5230;&#x3002;</p>
<blockquote>
<p>OpenSBI &#x5C06;&#x81EA;&#x8EAB;&#x653E;&#x5728; <code>0x80000000</code> &#xFF0C;&#x5B8C;&#x6210;&#x521D;&#x59CB;&#x5316;&#x540E;&#x4F1A;&#x8DF3;&#x8F6C;&#x5230; <code>0x80200000</code> &#xFF0C;&#x56E0;&#x6B64; <code>_start</code> &#x5FC5;&#x987B;&#x4F4D;&#x4E8E;&#x8FD9;&#x4E2A;&#x5730;&#x5740;&#x3002;<code>.text</code> &#x4E3A;&#x4EE3;&#x7801;&#x6BB5;&#x6807;&#x8BC6;&#xFF0C;&#x5176;&#x7B2C;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x5C31;&#x662F; <code>_start</code> &#x3002;</p>
</blockquote>
<p>&#x8FD9;&#x91CC;&#x9762;&#x6709;&#x4E24;&#x4E2A;&#x8F93;&#x5165;&#x6BB5;&#x4E0E;&#x5176;&#x4ED6;&#x957F;&#x7684;&#x4E0D;&#x592A;&#x4E00;&#x6837;&#xFF0C;&#x5373; <em>.text.entry,.bss.stack</em> &#xFF0C;&#x4F3C;&#x4E4E;&#x7F16;&#x8BD1;&#x5668;&#x4E0D;&#x4F1A;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x8FD9;&#x6837;&#x540D;&#x5B57;&#x7684;&#x6BB5;&#x3002;&#x4E8B;&#x5B9E;&#x4E0A;&#xFF0C;&#x5B83;&#x4EEC;&#x662F;&#x6211;&#x4EEC;&#x5728;&#x540E;&#x9762;&#x81EA;&#x5DF1;&#x5B9A;&#x4E49;&#x7684;&#x3002;</p>
<h3 id="&#x4F7F;&#x7528;&#x94FE;&#x63A5;&#x811A;&#x672C;">&#x4F7F;&#x7528;&#x94FE;&#x63A5;&#x811A;&#x672C;</h3>
<p>&#x4E3A;&#x4E86;&#x5728;&#x7F16;&#x8BD1;&#x65F6;&#x4F7F;&#x7528;&#x4E0A;&#x9762;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x94FE;&#x63A5;&#x811A;&#x672C;&#xFF0C;&#x6211;&#x4EEC;&#x5728; <code>.cargo/config</code> &#x6587;&#x4EF6;&#x4E2D;&#x52A0;&#x5165;&#x4EE5;&#x4E0B;&#x914D;&#x7F6E;&#xFF1A;</p>
<pre class="language-"><code class="lang-toml"><span class="token punctuation">[</span><span class="token table class-name">target.riscv64imac-unknown-none-elf</span><span class="token punctuation">]</span>
<span class="token key property">rustflags</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span>
    <span class="token string">&quot;-C&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;link-arg=-Tsrc/boot/linker64.ld&quot;</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span>
</code></pre>
<p>&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x662F;&#x5728;&#x94FE;&#x63A5;&#x65F6;&#x4F20;&#x5165;&#x4E00;&#x4E2A;&#x53C2;&#x6570; <code>-T</code> &#x6765;&#x6307;&#x5B9A;&#x4F7F;&#x7528;&#x54EA;&#x4E2A;&#x94FE;&#x63A5;&#x811A;&#x672C;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x91CD;&#x65B0;&#x7F16;&#x8BD1;&#x4E00;&#x4E0B;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x6B21;&#x67E5;&#x770B;&#x751F;&#x6210;&#x7684;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&#xFF1A;</p>
<pre class="language-"><code class="lang-sh">$ cargo build
<span class="token punctuation">..</span>.
    Finished dev <span class="token punctuation">[</span>unoptimized + debuginfo<span class="token punctuation">]</span> target<span class="token punctuation">(</span>s<span class="token punctuation">)</span> <span class="token keyword">in</span> <span class="token number">0</span>.23s
$ rust-objdump target/riscv64imac-unknown-none-elf/debug/os -h --arch-name<span class="token operator">=</span>riscv64

target/riscv64imac-unknown-none-elf/debug/os:    <span class="token function">file</span> <span class="token function">format</span> ELF64-riscv

Sections:
Idx Name          Size     VMA          Type
  <span class="token number">0</span>               00000000 0000000000000000
  <span class="token number">1</span> .text         00001000 0000000080200000 TEXT
  <span class="token number">2</span> .rodata       00000000 0000000080201000 TEXT
  <span class="token number">3</span> .data         00000000 0000000080201000 TEXT
  <span class="token number">4</span> .bss          00000000 0000000080201000 BSS
<span class="token punctuation">..</span>.
$ rust-objdump target/riscv64imac-unknown-none-elf/debug/os -d --arch-name<span class="token operator">=</span>riscv64

target/riscv64imac-unknown-none-elf/debug/os:    <span class="token function">file</span> <span class="token function">format</span> ELF64-riscv


Disassembly of section .text:

0000000080200000 stext:
<span class="token number">80200000</span>: <span class="token number">41</span> <span class="token number">11</span>                            addi    sp, sp, -16
<span class="token number">80200002</span>: 06 e4                            sd    ra, <span class="token number">8</span><span class="token punctuation">(</span>sp<span class="token punctuation">)</span>
<span class="token number">80200004</span>: <span class="token number">22</span> e0                            sd    s0, <span class="token number">0</span><span class="token punctuation">(</span>sp<span class="token punctuation">)</span>
<span class="token number">80200006</span>: 00 08                            addi    s0, sp, <span class="token number">16</span>
<span class="token number">80200008</span>: 09 a0                            j    <span class="token number">2</span>
8020000a: 01 a0                            j    <span class="token number">0</span>
        <span class="token punctuation">..</span>.
</code></pre>
<p>&#x7A0B;&#x5E8F;&#x5DF2;&#x7ECF;&#x88AB;&#x6B63;&#x786E;&#x5730;&#x653E;&#x5728;&#x4E86;&#x6307;&#x5B9A;&#x7684;&#x5730;&#x5740;&#x4E0A;&#x3002;</p>
<p>&#x5230;&#x8FD9;&#x91CC;&#xFF0C;&#x6211;&#x4EEC;&#x6E05;&#x695A;&#x4E86;&#x6700;&#x7EC8;&#x7A0B;&#x5E8F;&#x7684;&#x5185;&#x5B58;&#x5E03;&#x5C40;&#x4F1A;&#x957F;&#x6210;&#x4EC0;&#x4E48;&#x6837;&#x5B50;&#x3002;&#x4E0B;&#x4E00;&#x8282;&#x6211;&#x4EEC;&#x6765;&#x8865;&#x5145;&#x8FD9;&#x4E2A;&#x94FE;&#x63A5;&#x811A;&#x672C;&#x4E2D;&#x672A;&#x5B9A;&#x4E49;&#x7684;&#x6BB5;&#xFF0C;&#x5E76;&#x5B8C;&#x6210;&#x7F16;&#x8BD1;&#x3002;</p>
<p><div id="page-footer" class="localized-footer"><hr><p><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css"></p>
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<div id="gitalk-container"></div>
<script>
  var gitalk = new Gitalk({
    clientID: "ab871063a9fa7f1da571",
    clientSecret: "4760b384e3e452d2241d859cfa6a7da21a8729ec",
    repo: "rCore_tutorial_doc",
    owner: "rcore-os",
    admin: [
      "chyyuu",
      "xyongcn",
      "wangrunji0408",
      "xy-plus",
      "PanQL",
      "wyfcyx",
      "equation314"
    ],
    id: location.pathname,
    distractionFreeMode: false
  });
  gitalk.render("gitalk-container");
</script>
</div></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="part2.html" class="navigation navigation-prev " aria-label="Previous page: 编译、生成内核镜像">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="part4.html" class="navigation navigation-next " aria-label="Next page: [重写程序入口点 -start]">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"使用链接脚本指定内存布局","level":"1.4.3","depth":2,"next":{"title":"[重写程序入口点 -start]","level":"1.4.4","depth":2,"path":"chapter2/part4.md","ref":"chapter2/part4.md","articles":[]},"previous":{"title":"编译、生成内核镜像","level":"1.4.2","depth":2,"path":"chapter2/part2.md","ref":"chapter2/part2.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["hide-element","chapter-fold","katex","alerts","emphasize","-highlight","prism","localized-footer","mermaid-gb3"],"pluginsConfig":{"chapter-fold":{},"prism":{"css":["prismjs/themes/prism-tomorrow.css"]},"emphasize":{},"search":{},"localized-footer":{"filename":"extensions/comment/gitalk.html","hline":"true"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"hide-element":{"elements":[".gitbook-link"]},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"alerts":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter2/part3.md","mtime":"2020-09-09T11:31:56.891Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-09-10T06:57:01.716Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    <script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

